package impl.sort;

import anaydis.sort.SorterType;

import java.util.Comparator;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Tomi
 * Date: 23/08/2011
 * Time: 17:35:03
 * To change this template use File | Settings | File Templates.
 */
public class InsertionSorter extends AbstractSorter {
    public InsertionSorter(){
        super(SorterType.INSERTION);
    }
    public <T> void sort(Comparator<T> c, List<T> list) {
        for(int i=0; i<list.size(); i++){
            for(int j=i; j>0; j--){
                if(greater(c, list, j-1, j)){
                    swap(list, j-1, j);
                }else{
                    break;
                }
            }
        }
    }
}